#define _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>
#include<stdbool.h>

struct TreeNode {
    int val;
    struct TreeNode* left;
    struct TreeNode* right;
};

bool isUnivalTree(struct TreeNode* root) {
    if (root->left == NULL && root->right == NULL)
    {
        return true;
    }
    if (root->left == NULL)
    {
        return root->right->val == root->val && isUnivalTree(root->right);
    }
    if (root->right == NULL)
    {
        return root->left->val == root->val && isUnivalTree(root->left);
    }

    if (root->val == root->left->val && root->left->val == root->right->val)
    {
        return isUnivalTree(root->left) && isUnivalTree(root->right);
    }
    return false;
}